Fix reactions and DM messages lost during iCloud sync - #262
Open
FrankBStack wants to merge 1 commit into
Open
Conversation
Reactions pulled from iCloud carry Apple's "p:<part>/<guid>" form in associatedMessageGuid, but locally reactions are linked by the bare guid, so restored tapbacks never attached to their message. Strip the prefix on sync and use the part number from it when present. Cloud sync also routes DM messages by chatIdentifier, which chats created live in the app never set. Set it at creation time, and when a synced message still doesn't resolve, fall back to matching a DM by participant address and then to the group id in proto4 before giving up. A one-time repair on startup rewrites any already-stored prefixed reaction guids, backfills chatIdentifier on existing DMs, and clears the sync checkpoints so previously skipped messages get picked up on the next pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related problems with messages pulled from iCloud:
Reactions never attached. The cloud stores the reaction target as
p:<part>/<guid>, but locally reactions are linked by the bare guid, so every restored tapback ended up orphaned.Message.fromCloudnow strips the prefix and uses the part number from it when present (falling back to the attributedBody range lookup as before).DM messages were dropped. Cloud sync routes DM messages by
chatIdentifier, which chats created live in the app never populated. Those messages were silently skipped while the sync checkpoint still advanced, so they were never retried.createChatnow setschatIdentifierto the participant address for 1:1 chats.One-time repair on startup (guarded by prefs flags so it runs once):
associatedMessageGuid.chatIdentifieron existing single-handle chats.That last point means the first sync after updating will walk the full cloud history again. I couldn't see a cheaper way to recover the dropped messages since the checkpoint had already moved past them, but happy to gate it differently if you'd rather.
Likely addresses the empty-chat symptom in #212.
Will fix: #212 (the "some chats pop up empty" symptom is the dropped-DM case above).